using System;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.Mvc;

/**
 *  Our helpers, if we want to reduce something repetetive in our views
 */

namespace VERKProjectHopur16.Helpers
{
    public static class Lang
    {
        /**
         *  It's very boring to have GetGlobalResourceObject("Section", "Key").ToString() everywhere
         *  So we added Lang.GetText to help us
         *  Gives us the ability to change how we manage localization later on, for example
         *  we _do_ want to move this to a DB later on so that we can more easilty add / alter
         *  translation
         *  
         * Usage:
         *  In a view: 
         *      Html.ActionLink(Lang.GetText("Menu", "Events")...);
         *  
         *  Remember: To Import our Helpers in the .Master view file
         */
        public static string GetText(string section, string key)
        {
            //TODO: Add exception if the key isn't found in any of the resource files and handle it
            //ourselves
            try
            {
                string html = HttpContext.GetGlobalResourceObject(section, key).ToString();
                return html.ToString();
            }
            catch (NullReferenceException)
            {
                return "STRING " + key + " NOT TRANSLATED ";
            }
        }

        public static string GetFlag(Object sessionLang)
        {
            var langId = sessionLang != null ? sessionLang.ToString() : "all";

            var lang = "all";
            switch (langId) 
            { 
                case "1": 
                    lang = "en"; 
                    break; 
                case "2": 
                    lang = "is"; 
                    break; 
                case "3": 
                    lang = "se"; 
                    break; 
                default: break; 
            }  

            return lang;
        }

    }

    /*
     * 
    public static class ImageAction
    {
        public static string ImageAction(this HtmlHelper helper, string url, string act, string ctrl, object routeValues)
        {
            var builder = new TagBuilder("img");
            builder.MergeAttribute("src", url);
            builder.MergeAttribute("alt", "Change language");
            var link = helper.ActionLink("[placeholder]", act, ctrl, routeValues);

        }
    }
     */

}

